package com.fanhao.dllo.soundfm.utils;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

import com.fanhao.dllo.soundfm.R;

/**
 * Created by dllo on 16/1/16.
 */
public class PlayDialog extends ProgressDialog {
    private AnimationDrawable animationDrawable;
    private int resId;
    private ImageView playDialogIv;


    public PlayDialog(Context context, int resId) {
        super(context);
        this.resId = resId;
        //设置后,点击时,dialog不会消失
        setCanceledOnTouchOutside(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();


    }

    private void initData() {
        playDialogIv.setBackgroundResource(resId);
        // 通过ImageView对象拿到背景显示的AnimationDrawable
        animationDrawable = (AnimationDrawable) playDialogIv.getBackground();
        // 为了防止在onCreate方法中只显示第一帧的解决方案之一
        playDialogIv.post(new Runnable() {
            @Override
            public void run() {
                animationDrawable.start();
            }
        });
    }

    private void initView() {
        setContentView(R.layout.play_dialog_view);
        playDialogIv = (ImageView)findViewById(R.id.iv_loadingDialog);
    }


}
